<?php


namespace app\validate;

use app\model\GameCategoryModel;
use think\Validate;



class CategoryValidate extends Validate
{
    protected $rule = [
        'name'  => 'require|max:32|unique:game_category',
        'order' => 'require|integer|>=:0|<=:99999',
    ];

    protected $message = [
        'name.require'   => '分类名称不能为空',
        'name.max'       => '分类名称不能超过32字符',
        'name.unique'    => '分类名称已存在',
        'order.require'  => '排序值不能为空',
        'order.integer'  => '排序值必须为整数',
        'order.>='       => '排序值不能小于0',
        'order.<='       => '排序值不能超过99999'
    ];

    protected $scene = [
        'create' => ['name', 'order']
    ];

    // 编辑场景校验
    public function sceneEdit()
    {
        return $this->only(['name','order'])
            ->remove('name', 'unique')
            ->append('name', 'unique:game_category,name,{{id}}');
    }
}